load("//bazel:ray.bzl", "ray_cc_library", "ray_cc_test")

ray_cc_library(
    name = "scheduler",
    linkopts = select({
        "@platforms//os:windows": [
        ],
        "@platforms//os:macos": [
            "-pthread",
        ],
        "@platforms//os:linux": [
            "-lpthread",
        ],
        "//conditions:default": [],
    }),
    deps = [
        ":affinity_with_bundle_scheduling_policy",
        ":bundle_scheduling_policy",
        ":cluster_resource_manager",
        ":cluster_resource_scheduler",
        ":cluster_task_manager",
        ":composite_scheduling_policy",
        ":hybrid_scheduling_policy",
        ":bin_pack_scheduling_policy",
        ":local_resource_manager",
        ":node_affinity_scheduling_policy",
        ":node_label_scheduling_policy",
        ":random_scheduling_policy",
        ":spread_scheduling_policy",
    ],
)

ray_cc_library(
    name = "scheduler_internal",
    hdrs = ["internal.h"],
    deps = [
        "//src/ray/common:ray_object",
        "//src/ray/common:task_common",
        "//src/ray/protobuf:node_manager_cc_proto",
    ],
)

ray_cc_library(
    name = "cluster_resource_manager",
    srcs = ["cluster_resource_manager.cc"],
    hdrs = ["cluster_resource_manager.h"],
    deps = [
        ":local_resource_manager",
        "//src/ray/common:grpc_util",
        "//src/ray/common:ray_config",
        "//src/ray/common:task_common",
        "//src/ray/protobuf:gcs_cc_proto",
        "//src/ray/util:container_util",
        "//src/ray/util:logging",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_googletest//:gtest_prod",
    ],
)

ray_cc_library(
    name = "cluster_resource_scheduler",
    srcs = ["cluster_resource_scheduler.cc"],
    hdrs = ["cluster_resource_scheduler.h"],
    deps = [
        ":cluster_resource_manager",
        ":composite_scheduling_policy",
        ":scheduler_internal",
        "//src/ray/protobuf:gcs_cc_proto",
        "//src/ray/util:logging",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_googletest//:gtest_prod",
    ],
)

ray_cc_library(
    name = "cluster_task_manager",
    srcs = [
        "cluster_task_manager.cc",
        "scheduler_stats.cc",
    ],
    hdrs = [
        "cluster_task_manager.h",
        "scheduler_stats.h",
    ],
    deps = [
        ":cluster_resource_scheduler",
        ":cluster_task_manager_interface",
        ":local_task_manager_interface",
        ":scheduler_internal",
        ":scheduler_resource_reporter",
        "//src/ray/common:ray_config",
        "//src/ray/common:ray_object",
        "//src/ray/common:task_common",
        "//src/ray/stats:stats_lib",
        "//src/ray/util:logging",
        "@com_google_absl//absl/container:flat_hash_map",
    ],
)

ray_cc_library(
    name = "cluster_task_manager_interface",
    hdrs = ["cluster_task_manager_interface.h"],
    deps = [
        "//:rpc_server_call",
        "//src/ray/protobuf:node_manager_cc_proto",
    ],
)

ray_cc_library(
    name = "local_task_manager_interface",
    hdrs = ["local_task_manager_interface.h"],
    deps = [
        ":scheduler_internal",
        "//src/ray/common:task_common",
        "@com_google_absl//absl/container:flat_hash_map",
    ],
)

ray_cc_library(
    name = "local_resource_manager",
    srcs = ["local_resource_manager.cc"],
    hdrs = ["local_resource_manager.h"],
    deps = [
        "//src/ray/gcs/gcs_client:gcs_client_lib",
        "//src/ray/common:grpc_util",
        "//src/ray/common:ray_config",
        "//src/ray/common:ray_syncer",
        "//src/ray/common:task_common",
        "//src/ray/protobuf:gcs_cc_proto",
        "//src/ray/protobuf:node_manager_cc_proto",
        "//src/ray/util:logging",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_googletest//:gtest_prod",
    ],
)

ray_cc_library(
    name = "scheduler_resource_reporter",
    srcs = ["scheduler_resource_reporter.cc"],
    hdrs = ["scheduler_resource_reporter.h"],
    deps = [
        ":local_task_manager_interface",
        ":scheduler_internal",
        "//src/ray/common:ray_config",
        "//src/ray/common:task_common",
        "@com_google_absl//absl/container:flat_hash_map",
    ],
)

ray_cc_library(
    name = "scheduling_options",
    hdrs = ["policy/scheduling_options.h"],
    deps = [
        ":scheduling_context",
        "//src/ray/common:ray_config",
    ],
)

ray_cc_library(
    name = "scheduling_context",
    hdrs = ["policy/scheduling_context.h"],
    deps = [
        "//src/ray/common:id",
        "//src/ray/common:task_common",
        "@com_google_absl//absl/container:flat_hash_map",
    ],
)

ray_cc_library(
    name = "affinity_with_bundle_scheduling_policy",
    srcs = ["policy/affinity_with_bundle_scheduling_policy.cc"],
    hdrs = ["policy/affinity_with_bundle_scheduling_policy.h"],
    deps = [
        ":scheduling_policy",
        "//src/ray/common:task_common",
    ],
)

ray_cc_library(
    name = "bundle_scheduling_policy",
    srcs = ["policy/bundle_scheduling_policy.cc"],
    hdrs = ["policy/bundle_scheduling_policy.h"],
    deps = [
        ":cluster_resource_manager",
        ":scheduling_context",
        ":scheduling_policy",
        ":scorer",
        "//src/ray/common:task_common",
    ],
)

ray_cc_library(
    name = "composite_scheduling_policy",
    srcs = ["policy/composite_scheduling_policy.cc"],
    hdrs = ["policy/composite_scheduling_policy.h"],
    deps = [
        ":affinity_with_bundle_scheduling_policy",
        ":bundle_scheduling_policy",
        ":cluster_resource_manager",
        ":hybrid_scheduling_policy",
        ":bin_pack_scheduling_policy",
        ":node_affinity_scheduling_policy",
        ":node_label_scheduling_policy",
        ":random_scheduling_policy",
        ":spread_scheduling_policy",
    ],
)

ray_cc_library(
    name = "hybrid_scheduling_policy",
    srcs = ["policy/hybrid_scheduling_policy.cc"],
    hdrs = ["policy/hybrid_scheduling_policy.h"],
    deps = [
        ":scheduling_policy",
        "@com_google_absl//absl/random",
        "@com_google_absl//absl/random:bit_gen_ref",
        "@com_google_googletest//:gtest_prod",
    ],
)

ray_cc_library(
    name = "bin_pack_scheduling_policy",
    srcs = ["policy/bin_pack_scheduling_policy.cc"],
    hdrs = ["policy/bin_pack_scheduling_policy.h"],
    deps = [
        ":scheduling_policy",
    ],
)

ray_cc_library(
    name = "node_affinity_scheduling_policy",
    srcs = ["policy/node_affinity_scheduling_policy.cc"],
    hdrs = ["policy/node_affinity_scheduling_policy.h"],
    deps = [
        ":hybrid_scheduling_policy",
        ":scheduling_policy",
    ],
)

ray_cc_library(
    name = "node_label_scheduling_policy",
    srcs = ["policy/node_label_scheduling_policy.cc"],
    hdrs = ["policy/node_label_scheduling_policy.h"],
    deps = [
        ":scheduling_context",
        ":scheduling_policy",
    ],
)

ray_cc_library(
    name = "random_scheduling_policy",
    srcs = ["policy/random_scheduling_policy.cc"],
    hdrs = ["policy/random_scheduling_policy.h"],
    deps = [":scheduling_policy"],
)

ray_cc_library(
    name = "spread_scheduling_policy",
    srcs = ["policy/spread_scheduling_policy.cc"],
    hdrs = ["policy/spread_scheduling_policy.h"],
    deps = [
        ":hybrid_scheduling_policy",
        ":scheduling_policy",
        "//src/ray/util:container_util",
    ],
)

ray_cc_library(
    name = "scorer",
    srcs = ["policy/scorer.cc"],
    hdrs = ["policy/scorer.h"],
    deps = ["//src/ray/common:task_common"],
)

ray_cc_library(
    name = "scheduling_policy",
    hdrs = ["policy/scheduling_policy.h"],
    deps = [
        ":scheduling_options",
        "//src/ray/common:task_common",
    ],
)

ray_cc_test(
    name = "cluster_resource_scheduler_test",
    size = "small",
    srcs = [
        "cluster_resource_scheduler_test.cc",
    ],
    tags = ["team:core"],
    deps = [
        "//:ray_mock",
        "//:raylet_lib",
        "//src/ray/common:test_util",
        "@com_google_googletest//:gtest_main",
    ],
)

ray_cc_test(
    name = "local_resource_manager_test",
    size = "small",
    srcs = [
        "local_resource_manager_test.cc",
    ],
    tags = ["team:core"],
    deps = [
        "//:ray_mock",
        "//:raylet_lib",
        "@com_google_googletest//:gtest_main",
    ],
)

ray_cc_test(
    name = "cluster_resource_scheduler_2_test",
    size = "small",
    srcs = [
        "cluster_resource_scheduler_2_test.cc",
    ],
    tags = ["team:core"],
    deps = [
        "//:raylet_lib",
        "@com_google_googletest//:gtest_main",
    ],
)

ray_cc_test(
    name = "scheduling_policy_test",
    size = "small",
    srcs = [
        "policy/scheduling_policy_test.cc",
    ],
    tags = ["team:core"],
    deps = [
        "//:raylet_lib",
        "@com_google_googletest//:gtest_main",
    ],
)

ray_cc_test(
    name = "hybrid_scheduling_policy_test",
    size = "small",
    srcs = [
        "policy/hybrid_scheduling_policy_test.cc",
    ],
    tags = ["team:core"],
    deps = [
        ":scheduler",
        "@com_google_absl//absl/random:mock_distributions",
        "@com_google_googletest//:gtest_main",
    ],
)

ray_cc_test(
    name = "cluster_task_manager_test",
    size = "small",
    srcs = [
        "cluster_task_manager_test.cc",
    ],
    tags = ["team:core"],
    deps = [
        "//:ray_mock",
        "//:raylet_lib",
        "//src/ray/common:test_util",
        "@com_google_googletest//:gtest_main",
    ],
)

ray_cc_test(
    name = "cluster_resource_manager_test",
    size = "small",
    srcs = [
        "cluster_resource_manager_test.cc",
    ],
    tags = ["team:core"],
    deps = [
        "//:raylet_lib",
        "@com_google_googletest//:gtest_main",
    ],
)
